#include "misc/arch.hpp"

#include <unistd.h>

namespace rewine {

#if defined(__x86_64__)
machine_t g_machine = machine_t::MACHINE_AMD64;
#elif defined(__i386__)
machine_t g_machine = machine_t::MACHINE_I386;
#else
#error "unknown arch"
#endif

int g_szPointer = sizeof(void *);

static long page_size = 0;

long
get_page_size() {
    if (!page_size) {
        page_size = ::sysconf(_SC_PAGESIZE);
    }
    return page_size;
}

long
get_page_mask() {
    return get_page_size() - 1;
}

std::string
to_string(machine_t machine) {
    return std::to_string(static_cast<int>(machine));
}

} // namespace rewine
